score_id = 2;

clear feat_cand

for i = 1:11
    feat_cand{i} = [i];
    feat_cand{i+11} = [ 1 i ];
end

n = 22;

for i = 3:11
    n = n+1;
    feat_cand{n} = 1:i;
end

n = n+1;
feat_cand{n} = [1 5 9];

%feat_cand{23} = [1,2,3,4,9];

method_cand = [1 2 6 7];

fout = fopen('ValiOutput.txt', 'wt');

genNameList;

for i = 1:length(feat_cand)
    
    feat_id = feat_cand{i};
    
    for method_id = method_cand
        vali_name = [ './vali_result/vali_' method_name{method_id} '_feat' ];

        for k = feat_id
            vali_name = [vali_name num2str( k ) ];
        end

        vali_name = [vali_name '_on_' ...
                    score_name{score_id} '.mat'];

        try
            load(vali_name,'vali');
        catch
            continue;
        end
        
        if(length(vali)<3), continue, end
        
        fprintf( fout, '%s\t', method_name{ method_id } );
        
        sum_F_res = vali{1}.act_F_res;
        for j = 2:length(vali);
            sum_F_res = sum_F_res + vali{j}.act_F_res;
        end        
        [~,pick_k] = max(sum_F_res); pick_k = pick_k(1);
        pick_k = 19;
        
        for j = 1:length(vali);
            fprintf(fout, '%.3f\t', vali{j}.act_F_res( pick_k ) );
        end
        
        for j = 1:length(feat_id)            
            k = feat_id(j);
            fprintf(fout,'%s',short_name{k} );
            if(j~=length(feat_id)), fprintf(fout,'+'),end
        end
        
        fprintf(fout, '\t');        
        
        for j = 1:length(feat_id)            
            k = feat_id(j);
            fprintf(fout,'%s',feature_name{k} );
            if(j~=length(feat_id)), fprintf(fout,' + '),end
        end
        
        fprintf(fout, '\n');        
        
%         plot(1:20, vali{2}.act_F_res)
%         hold on
    end        
end

%%


score_id = 2;

feat_id = [1 5 9];

method_cand = [1 2 7 8];

genNameList;

score_mat = zeros( length(method_cand),3);

for i = 1:length(method_cand)
    method_id = method_cand(i);
    vali_name = [ './vali_result/vali_' method_name{method_id} '_feat' ];

    for k = feat_id
        vali_name = [vali_name num2str( k ) ];
    end

    vali_name = [vali_name '_on_' ...
                score_name{score_id} '.mat'];

    try
        load(vali_name,'vali');
    catch
        continue;
    end

    if(length(vali)<3), continue, end

    pick_k = 19;

    for j = 1:length(vali);
        score_mat(i,j) = vali{j}.act_F_res( pick_k );            
    end
end


fid = fopen('TableRecommModel.tex','wt');

fprintf(fid,'\\begin{table}[tb]\n');
fprintf(fid,'\t\\footnotesize\n');
fprintf(fid,'\t\\centering\n');
fprintf(fid,'\t\\caption{Recommendation with Dense Probe}\n');
fprintf(fid,'\t\\label{glb_feats}\n');
fprintf(fid,'\t\\begin{tabular}{| l |');
for i = 1:size(score_mat,1) -1
    fprintf( fid ,'c|');
end
fprintf(fid,'}\n');
fprintf(fid,'\t\\hline\n');
fprintf(fid,['\t'...            
            '\t& EDSH '...
            '\t& kitchen	'...
            '\\\\ \\hline\n']);
        
for i = 1:length(method_cand)
    fprintf(fid,'\t%s ',method_name{ method_cand(i) });
    
    for j = 2:3
        if(score_mat(i,j)>0.1)
            fprintf(fid,'\t & %.3f ',score_mat(i,j));
        else
            fprintf(fid,'\t & NaN ',score_mat(i,j));
        end            
    end
    
    fprintf(fid,'\\\\\\hline\n');
    
end

fprintf(fid,'\t\\end{tabular}\n');
fprintf(fid,'\t\\vspace{-4mm}\n');
fprintf(fid,'\\end{table}\n');

fclose(fid);

%%


score_id = 2;

clear feat_cand

for i = 1:11
    feat_cand{i} = [i];
    feat_cand{i+11} = [ 1 i ];
end

method_id = 1;

genNameList;

score_mat = zeros(  length(feat_cand),3);

for i = 1:length(feat_cand)
    feat_id = feat_cand{i};
    vali_name = [ './vali_result/vali_' method_name{method_id} '_feat' ];

        for k = feat_id
            vali_name = [vali_name num2str( k ) ];
        end

        vali_name = [vali_name '_on_' ...
                    score_name{score_id} '.mat'];

        try
            load(vali_name,'vali');
        catch
            continue;
        end
        
        if(length(vali)<3), continue, end
        
        pick_k = 19;
        
        for j = 1:length(vali);
            score_mat(i,j) = vali{j}.act_F_res( pick_k );            
        end
end

table_mat = [score_mat(2:11,2:3) score_mat(13:22,2:3)];
table_mat(10,3:4) = score_mat(1,2:3);

for i = 1:9
    table_name{i} = feature_name{i+1};
end

table_name{10} = ' ';

fid = fopen('TableGlobalFeat.tex','wt');

fprintf(fid,'\\begin{table}[tb]\n');
fprintf(fid,'\t\\footnotesize\n');
fprintf(fid,'\t\\centering\n');
fprintf(fid,'\t\\caption{Different Global Feature}\n');
fprintf(fid,'\t\\label{glb_feats}\n');
fprintf(fid,'\t\\begin{tabular}{| l |');
for i = 1:4
    fprintf( fid ,'c|');
end
fprintf(fid,'}\n');
fprintf(fid,'\t\\hline\n');
fprintf(fid,['\t'...
            '\t&    '...
            '\t& 	'...
            '\t& +CC	'...
            '\t& +CC	'...
            '\\\\ \\hline\n']);
fprintf(fid,['\t'...
            '\t&  EDSH2  '...
            '\t& EDSH-kitchen	'...
            '\t& EDSH2	'...
            '\t& EDSH-kitchen	'...
            '\\\\ \\hline\n']);
        
for i = 1:length(table_name)
    fprintf(fid,'\t%s ',table_name{i});
    
    for j = 1:4
        if(table_mat(i,j)>0.1)
            fprintf(fid,'\t & %.3f ',table_mat(i,j));
        else
            fprintf(fid,'\t & NaN ',table_mat(i,j));
        end            
    end
    
    fprintf(fid,'\\\\\\hline\n');
    
end

fprintf(fid,'\t\\end{tabular}\n');
fprintf(fid,'\t\\vspace{-4mm}\n');
fprintf(fid,'\\end{table}\n');

fclose(fid);